
using B.S.RbacData.Infrastructure;
using IGeekFan.AspNetCore.Knife4jUI;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using SupplierCustomerManagement.Infrastructure;
using SupplierCustomerManagement.Write.API.Automappers;
using SupplierCustomerManagement.Write.API.Services;
using System.Reflection;

namespace SupplierCustomerManagement.Write.API
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.
            //ע�����ݿ�������
            builder.Services.AddDbContext<SupplierDbContext>(options =>
            {
                options.UseMySql(builder.Configuration.GetConnectionString("mysql"), new MySqlServerVersion("5.7"));
            });
            //ע���Զ�ӳ��
            builder.Services.AddAutoMapper(typeof(AutomapperProfiles));
            //ע���н���ģʽ
            builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
            //ע��ִ�
            builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
            //ע��Nlog
            builder.Host.UseNLog();
            // 注册Minio服务
            builder.Services.AddScoped<IMinioService, MinioService>();

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen(o =>
            {

                //��ȡ��Ŀ����
                var pname = typeof(Program).Assembly.GetName().Name;

                var path = AppDomain.CurrentDomain.BaseDirectory + pname + ".xml";

                o.IncludeXmlComments(path, true);
            });

            var app = builder.Build();

            //ע�����
            app.UseCors(x=>x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                //app.UseSwaggerUI();
            }

            app.UseKnife4UI();

            app.UseHttpsRedirection();

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
